package com.sxt.bus.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.bus.domain.Car;
import com.sxt.bus.mapper.CarMapper;
import com.sxt.bus.service.CarService;
import com.sxt.bus.vo.CarVo;
import com.sxt.bus.vo.CarVo;
import com.sxt.sys.utils.DataGridView;
@Service
@Transactional
public class CarServiceImpl implements CarService {
@Autowired
	private CarMapper carMapper;
	@Override
	public DataGridView queryAllCar(CarVo carVo) {
		// TODO Auto-generated method stub
		Page<Object> page = PageHelper.startPage(carVo.getPage(),carVo.getRows());
		List<Car> list = carMapper.queryAllCar(carVo);
		System.out.println(page.getTotal());
		System.out.println(list.size());
		return new DataGridView(page.getTotal(),list);
	}
	@Override
	public void addCar(CarVo carVo) {
		// TODO Auto-generated method stub
		carMapper.insertSelective(carVo);
	}

	@Override
	public void updateCar(CarVo carVo) {
		// TODO Auto-generated method stub
		carMapper.updateByPrimaryKeySelective(carVo);
	}

	public void deleteCar(CarVo carVo) {
		// TODO Auto-generated method stub
		carMapper.deleteByPrimaryKey(carVo.getCarnumber());
	}
	@Override
	public Car selectByPrimaryKey(String carnumber) {
		// TODO Auto-generated method stub
		return carMapper.selectByPrimaryKey(carnumber);
	}

}
